package com.gongpb.langchain4j.demo.manus.tool;

import dev.langchain4j.agent.tool.ToolExecutionRequest;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ToolUtil {

    public static ToolResult runTool(ToolExecutionRequest toolExecutionRequest){

        try {
            Class<?> clz = Class.forName(toolExecutionRequest.name());
            Tool tool = (Tool) JsonUtil.fromJson(toolExecutionRequest.arguments(), clz);
            return tool.runTool();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
